package com.geek.novel.network

import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable



/**
 * Created by lfp on 2017/9/27.
 */
class DisposableManager private constructor(){

    private var compositeDisposable: CompositeDisposable? = null

    fun add(disposable: Disposable?) {
        getCompositeDisposable().add(disposable!!)
    }

    fun dispose() {
        getCompositeDisposable().dispose()
    }

    private fun getCompositeDisposable(): CompositeDisposable {
        if (compositeDisposable == null || compositeDisposable!!.isDisposed) {
            compositeDisposable = CompositeDisposable()
        }
        return compositeDisposable as CompositeDisposable
    }

    private object Holder { val INSTANCE = DisposableManager() }

    companion object {
        val instance: DisposableManager by lazy { Holder.INSTANCE }
    }


}